import pygame,time,random
pygame.init()
screen=pygame.display.set_mode([700,700])
screen.fill([0,255,0])
pygame.display.flip()

block=[70,70]
ditu=[
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0]
]
zz=[
[5,5],
[2,2,3,2,2],
[2,2,3,2,2],
[2,2,3,2,2],
[2,2,3,2,2],
[2,2,3,2,2],
]
dt=[
[5,5],
[2,2,3,2,2],
[2,2,3,2,2],
[2,2,3,2,2],
[2,2,2,2,2],
[2,2,2,2,2],
]
ld=[
[5,5],
[2,2,2,2,2],
[2,2,2,2,2],
[2,2,3,2,2],
[2,2,2,2,2],
[2,2,2,2,2],
]
zw=[
[5,5],
[2,2,3,2,2],
[2,2,3,2,2],
[3,3,3,2,2],
[2,2,2,2,2],
[2,2,2,2,2],
]
scl=[
[5,5],
[2,2,3,2,2],
[2,2,3,2,2],
[3,3,3,3,3],
[2,2,2,2,2],
[2,2,2,2,2],
]
szlk=[
[5,5],
[2,2,3,2,2],
[2,2,3,2,2],
[3,3,3,3,3],
[2,2,3,2,2],
[2,2,3,2,2],
]
lu=[zz,dt,ld,zw,scl,szlk]
caoc=([],[0,100,0],[0,0,0],[255,255,255])
def d(screen,cao,caoc,weizhi,daxiao):
    a=cao[0]
    a1=a[1]
    x=0
    y=0
    while x<a1:
        c=cao[x+1][y]
        if c==0:
            y+=1
            if y>a1-1:
                x+=1
                y=0
            continue
        else:
            pygame.draw.rect(screen,caoc[c],[weizhi[0]+y*daxiao[0],weizhi[1]+x*daxiao[1],daxiao[0],daxiao[1]],0)
        pygame.display.flip()
        y+=1
        if y>a1-1:
            x+=1
            y=0
            if x==5:
                pass
"""
def zhuan(lu,c):
    x=lu[0][0]
    y=lu[0][1]
    x1=0
    l=[]
    while x1<x:
        l.append(lu[x1+1])
        x1+=1
    lu=[[x,y]]
    x1=0
    while x1<x:
        x1+=1
        lu.append([])
    x1=0
    while x1<x:
        y1=0
        while y1<y:
            lu[x1+1].append(l[x1+1][y1])
            y1+=1
        x1+=1

def zhuan(lu,c):
    x=lu[0][0]
    y=lu[0][1]
    l=[]
    x1,y1=0,0
    while x1<x+1:    
        l.append(lu[x1])
        x1+=1
    lu=[[x,y]]
    x1=0
    while x1<x:
        x1+=1
        lu.append([])
    x1=0
    while x1<x:
        y1=0
        while y1<y:
            #print(l,x1,y1,lu)
            lu[y1+1].append(l[x1+1][y1])
            y1+=1
        x1+=1
    return lu
print(f"zw:{scl}")
print(zhuan(scl,2))

a=[[100],[200,[300]]]
del a[0]
print(a)
del a[0][1]
print(a)
"""
def zhuan(lu,c):
    x=lu[0][0]
    y=lu[0][1]
    if c==1:
        x1=0
        l=lu
        lu1=[]
        lu1.append(l[0])
        del l[0]
        while x1<x:
            x1+=1
            lu1.append([])
        x1=0
        while x1<x:
            y1=0
            while y1<y:
                #print(l,x1,y1,lu1)
                lu1[y-y1].append(l[x1][y1])
                y1+=1
            x1+=1
    if c==2:
        x1=0
        l=lu
        lu1=[]
        lu1.append(l[0])
        del l[0]
        while x1<x:
            x1+=1
            lu1.append([])
        x1=0
        while x1<x:
            y1=0
            while y1<y:
                #print(l,x1,y1,lu1)
                lu1[y-y1].append(l[x1][y1])
                y1+=1
            x1+=1
        
        x1=0
        l=lu1
        lu2=[]
        lu2.append(l[0])
        del l[0]
        while x1<x:
            x1+=1
            lu2.append([])
        x1=0
        while x1<x:
            y1=0
            while y1<y:
                #print(l,x1,y1,lu2)
                lu2[y-y1].append(l[x1][y1])
                y1+=1
            x1+=1
        lu1=lu2
    return lu1
print(f"zw:{scl}")
z1=zhuan(scl,1)
z2=zhuan(scl,2)
print(z1)
print(z2)



def drawditu(ditu,screen,lu,block,caoc):
    x=0
    y=0
    while x+y<20:
        pangbian=[0,0,0,0]
        dongxi=ditu[x][y]
        if dongxi>0:
            if x>0:
                pangbian[0]+=ditu[x-1][y]
            if x<10:
                pangbian[1]+=ditu[x+1][y]
            if y>0:
                pangbian[2]+=ditu[x][y-1]
            if y<10:
                pangbian[3]+=ditu[x][y+1]
            if pangbian[0]+pangbian[1]+pangbian[2]+pangbian[3]==0:
                d(screen,lu[2],caoc,[x*block[0],y*block[1]],[block[0],block[1]])
            if pangbian[0]+pangbian[1]+pangbian[2]+pangbian[3]==1:
                pass
            if pangbian[0]+pangbian[1]+pangbian[2]+pangbian[3]==2:
                pass
            if pangbian[0]+pangbian[1]+pangbian[2]+pangbian[3]==3:
                pass
            if pangbian[0]+pangbian[1]+pangbian[2]+pangbian[3]==4:
                d(screen,lu[5],caoc,[x*block[0],y*block[1]],[block[0],block[1]])
r=True
#d(screen,szlk,caoc,[200,200],[20,20])
while r:
    pygame.draw.rect(screen,[255,0,0],[0,0,30,20],0)
    for event in pygame.event.get():
        if  event.type == pygame.MOUSEBUTTONUP:
            if event.button==1:
                x1,y1=event.pos
                if x1<=30 and x1>0:
                    if y1<=20 and y1>0:
                        pygame.quit()
                        r=False
    if r:
        pygame.display.flip()
"""
"""
def zhuan(lu,c):
    x=lu[0][0]
    y=lu[0][1]
    l=[]
    x1,y1=0,0
    if x>y:
        while x1<x:
            l.append(lu[x1])
            x1+=1
            #print(l)
    if x<y:
        while y1<y:
            l.append(lu[y1])
            y1+=1
            #print(l)
    if x==y:
        while x1<x+1:    
            l.append(lu[x1])
            x1+=1
            #print(l)
    lu=[[x,y]]
    x1=0
    y1=0
    while x1<x or y1<y:
        x1+=1
        y1+=1
        lu.append([])
    x1=1
    if x>=y:
        while x1<x:
            y1=0
            x2=0
            if x>=y:
                while x2<x:
                    #print(l,x1,y1,lu,x,y)
                    lu[y1+1].append(l[x1][y1])
                    x2+=1
                    y1+=1
                    #print(y1,lu,l)
            if y>x:
                while y1<y:
                    #print(l,x1,y1,lu)
                    lu[y1+1].append(l[x1][y1])
                    y1+=1
                    #print(y1)
            x1+=1
    if y>x:
        while x1<x+1:
            y1=0
            if x>=y:
                while y1<x:
                    #print(l,x1,y1,lu)
                    lu[y1+1].append(l[x1][y1])
                    y1+=1
                    #print(y1)
            if y>x:
                while y1<y:
                    #print(l,x1,y1,lu)
                    lu[y1+1].append(l[x1][y1])
                    y1+=1
                    #print(y1)
            x1+=1
    return lu
lu=[
[4,4],
[1,2,3,4],
[5,6,7,8],
[9,10,11,12],
[13,14,15,16]
]
c=1
lu=zhuan(lu,c)
print (lu)
#print (lu[2])
#print (lu[3])
#print (lu[4])
















































"""
def zhuan(lu,c):
    x=lu[0][0]
    y=lu[0][1]
    l=[]
    x1,y1=0,0
    if x>y:
        while x1<x:
            l.append(lu[x1])
            x1+=1
    if x<y:
        while y1<y:
            l.append(lu[y1])
            y1+=1
    if x==y:
        while x1<x+1:    
            l.append(lu[x1])
            x1+=1
    lu=[[x,y]]
    x1=0
    y1=0
    while x1<x or y1<y:
        x1+=1
        y1+=1
        lu.append([])
    x1=1
    if x==y:
        while x1<x+1:
            y1=0
            x2=0
            if x>=y:
                while x2<x:
                    lu[y1+1].append(l[x1][y1])
                    x2+=1
                    y1+=1
            x1+=1
    if x>y:
        while x1<x:
            y1=0
            x2=0
            if x>=y:
                while x2<x:
                    lu[y1+1].append(l[x1][y1])
                    x2+=1
                    y1+=1
            x1+=1
    if y>x:
        while x1<x+1:
            y1=0
            if y>=x:
                while y1<y:
                    lu[y1+1].append(l[x1][y1])
                    y1+=1
            x1+=1
    return lu
lu=[
[3,4],
[1,2,3,4],
[5,6,7,8],
[9,10,11,12],
[13,14,15,16]
]
c=1
lu=zhuan(lu,c)
print(lu)"""